package com.promise.paging

import android.arch.paging.PagedListAdapter
import android.support.v7.util.DiffUtil
import android.view.ViewGroup

/**
 * Created by CQNNJ-003 on 2018/6/2.
 */
class UserPagedListAdapter : PagedListAdapter<QuestsData, UserViewHolder>(object : DiffUtil.ItemCallback<QuestsData>() {

    override fun areItemsTheSame(oldItem: QuestsData, newItem: QuestsData): Boolean =  oldItem == newItem

    override fun areContentsTheSame(oldItem: QuestsData, newItem: QuestsData): Boolean =  oldItem.name == newItem.name

}) {

    override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
        holder.bind(getItem(position))
    }

    override fun onBindViewHolder(holder: UserViewHolder, position: Int, payloads: MutableList<Any>) {
        if (payloads.isNotEmpty()) {
            val item = getItem(position)
            holder.updateScore(item)
        } else {
            onBindViewHolder(holder, position)
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder {
        return UserViewHolder.create(parent)
    }

}